package com.itheima_01;

import java.util.ArrayList;
import java.util.Iterator;

public class ArraylistDemo01 {
    public static void main(String[] args){
        ArrayList<Student> list = new ArrayList<>();
        Student s1=new Student("张三",23);
        Student s2=new Student("李四",24);
        Student s3=new Student("王五",25);

        list.add(s1);
        list.add(s2);
        list.add(s3);

        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println("姓名:"+s.getName()+",年龄:"+s.getAge());
        }

        System.out.println("-----------------------");
        Iterator<Student> it = list.iterator();
        while(it.hasNext()){
            Student s = it.next();
            System.out.println("姓名:"+s.getName()+",年龄:"+s.getAge());


        }

        System.out.println("-------------------------------");
        for (Student s : list) {
            System.out.println("姓名:"+s.getName()+",年龄:"+s.getAge());

        }
    }
}
